﻿using System;
using System.Drawing;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a table.
    /// </summary>
    [Serializable]
    public class Table : Element {
        /// <summary>
        /// Represents the possible choices for aligning a table.
        /// </summary>
        public enum AlignmentChoices {
            /// <summary>
            /// Aligns the table to the left of surrounding content.
            /// </summary>
            Left,
            /// <summary>
            /// Aligns the table to the right of surrounding content.
            /// </summary>
            Right,
            /// <summary>
            /// Aligns the table in the center of surrounding content.
            /// </summary>
            Center
        }

        /// <summary>
        /// Represents the possible framing choices for a table.
        /// </summary>
        public enum FrameChoices {
            /// <summary>
            /// Displays the border at the top of the table.
            /// </summary>
            Above,
            /// <summary>
            /// Displays the border at the bottom of the table.
            /// </summary>
            Below,
            /// <summary>
            /// Displays the border at the top and bottom of the table.
            /// </summary>
            HSides,
            /// <summary>
            /// Displays the border at the left and right of the table.
            /// </summary>
            VSides,
            /// <summary>
            /// Displays the border at the left of the table.
            /// </summary>
            Lhs,
            /// <summary>
            /// Displays the border at the right side of the table.
            /// </summary>
            Rhs,
            /// <summary>
            /// Displays the border on all sides of the table.
            /// </summary>
            Border,
            /// <summary>
            /// Displays the border on all sides of the table.
            /// </summary>
            Box,
            /// <summary>
            /// Displays no border on the table.
            /// </summary>
            Void
        }

        /// <summary>
        /// Represents the possible choices for ruling the table.
        /// </summary>
        public enum RuleChoices {
            /// <summary>
            /// No rules will be displayed on the table.
            /// </summary>
            None,
            /// <summary>
            /// Rules will be displayed between row and column groups.
            /// </summary>
            Groups,
            /// <summary>
            /// Rules will be displayed between rows.
            /// </summary>
            Rows,
            /// <summary>
            /// Rules will be displayed between columns.
            /// </summary>
            Columns,
            /// <summary>
            /// Rules will be displayed between both rows and columns.
            /// </summary>
            All
        }

        private AlignmentChoices? _align;
        private Color? _bgcolor;
        private int? _border;
        private int? _cellpadding;
        private int? _cellspacing;
        private FrameChoices? _frame;
        private RuleChoices? _rules;
        private string _summary;
        private string _width;

        /// <summary>
        /// Determines how the table is aligned relative to the surrounding
        /// content.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public AlignmentChoices? Align {
            get { return _align; }
            set { _align = value; }
        }

        /// <summary>
        /// Determines the background color of the table.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public Color? BGColor {
            get { return _bgcolor; }
            set { _bgcolor = value; }
        }

        /// <summary>
        /// Determines the width of the border around the table.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public int? Border {
            get { return _border; }
            set { _border = value; }
        }

        /// <summary>
        /// Determines the number of pixels to pad each cell with.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public int? CellPadding {
            get { return _cellpadding; }
            set { _cellpadding = value; }
        }

        /// <summary>
        /// Determines the number of pixels to space each cell by.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public int? CellSpacing {
            get { return _cellspacing; }
            set { _cellspacing = value; }
        }

        /// <summary>
        /// Determines how to draw a frame around the table.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public FrameChoices? Frame {
            get { return _frame; }
            set { _frame = value; }
        }

        /// <summary>
        /// Determines where to place rules in the table.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public RuleChoices? Rules {
            get { return _rules; }
            set { _rules = value; }
        }

        /// <summary>
        /// Determines the text shown to clients which cannot render a table.
        /// </summary>
        [Obsolete("Deprecated - consider using <caption> instead.")]
        public string Summary {
            get { return _summary; }
            set { _summary = value; }
        }

        /// <summary>
        /// Determines the width of the table.
        /// </summary>
        /// <remarks>Implemented as a string, so as to allow use of
        /// percentages.</remarks>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public string Width {
            get { return _width; }
            set { _width = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _align, "align", true);
            AttributeWriter.Write(sb, _bgcolor, "bgcolor");
            AttributeWriter.Write(sb, _border, "border");
            AttributeWriter.Write(sb, _cellpadding, "cellpadding");
            AttributeWriter.Write(sb, _cellspacing, "cellspacing");
            AttributeWriter.Write(sb, _frame, "frame", true);
            AttributeWriter.Write(sb, _rules, "rules", true);
            AttributeWriter.Write(sb, _summary, "summary");
            AttributeWriter.Write(sb, _width, "width");
        }
    }
}
